package com.tqjc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tqjc.common.VO.StockSteelBaseInfoVO;
import com.tqjc.entity.SteelPlate;
import com.tqjc.entity.StockSteels;
import com.tqjc.service.SteelPlateService;
import com.tqjc.service.StockSteelsService;
import com.tqjc.service.SysBusinessService;
import com.tqjc.system.core.model.AjaxJson;
import com.tqjc.system.core.model.PageInfo;
import com.tqjc.system.core.query.QueryUtils;
import com.tqjc.system.core.util.ResponseUtil;
import com.tqjc.wrapper.SteelPlateWrapper;
import com.tqjc.wrapper.StockSteelBaseInfoWrapper;
import com.tqjc.wrapper.StockSteelsWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Controller
@RequestMapping("/stockSteels")
public class SteelController {

    @Resource
    public StockSteelsService stockSteelsService;

    @Resource
    public SteelPlateService steelPlateService;

    @Autowired
    public SysBusinessService sysBusinessService;


    //辊道管理主页
    @RequestMapping("/index")
    public String index() {
        return "xg5msteel/manage/StockSteelsManage.html";
    }


    @RequestMapping("/getStockSteelBaseInfo")
    public void getStockSteelBaseInfo(String stockNo, HttpServletResponse response){
        StockSteelBaseInfoVO stockSteelBaseInfo = sysBusinessService.getStockSteelBaseInfo(stockNo);
        ResponseUtil.write(response, new StockSteelBaseInfoWrapper(stockSteelBaseInfo).wrap());
    }

    /**
     * 获取表格数据 树形结构
     *
     * @param
     * @param request
     * @return
     */
    @RequestMapping("/datagrid")
    @ResponseBody
    public void datagrid(StockSteels stockSteels, PageInfo<StockSteels> page, HttpServletRequest request, HttpServletResponse response) {
        //拼接查询条件
        QueryWrapper<StockSteels> queryWrapper = QueryUtils.installQueryWrapperRow(stockSteels, request.getParameterMap());

        //执行查询
        IPage<StockSteels> lstResult = stockSteelsService.page(page.getPageEntity(), queryWrapper);

        //结果处理,直接写到客户端
        ResponseUtil.write(response, new StockSteelsWrapper(lstResult).wrap());
    }

    @RequestMapping("/spdatagrid")
    @ResponseBody
    public void spdatagrid(SteelPlate steelPlate, PageInfo<SteelPlate> page, HttpServletRequest request, HttpServletResponse response) {
        //拼接查询条件
        QueryWrapper<SteelPlate> queryWrapper = QueryUtils.installQueryWrapperRow(steelPlate, request.getParameterMap());

        //执行查询
        IPage<SteelPlate> lstResult = steelPlateService.page(page.getPageEntity(), queryWrapper);

        //结果处理,直接写到客户端
        ResponseUtil.write(response, new SteelPlateWrapper(lstResult).wrap());
    }
}
